{layout name="common/layout" /}
{css href="__PUBLIC__/admin/js/bootstrap-daterangepicker/daterangepicker.css"}
{js href="__PUBLIC__/admin/js/bootstrap-daterangepicker/moment.min.js,__PUBLIC__/admin/js/bootstrap-daterangepicker/daterangepicker.js" /}
<section class="panel">
    <header class="panel-heading">
        会员列表 <span class="label label-default">{$member_count}人</span><a class="btn btn-default tools pull-right" href="javascript:location.reload();"><span class="fa fa-refresh"></span></a>
    </header>
    <div class="panel-body">
        <div class="adv-table">
            <div id="dynamic-table_wrapper" class="dataTables_wrapper form-inline" role="grid">
                <div class="row">
                    <div class="col-xs-4 btn-group">
                        <a class="btn btn-default disabled" role="operate" data-type="1" data-title="删除会员" data-url="{:WebUrl('adminmember/del')}"><i class="fa fa-trash-o"></i> 删除会员</a>
                        <a class="btn btn-default disabled"  role="operate" data-type="2" data-title="拉黑会员" data-url="{:WebUrl('adminmember/operatemember',array('is_black'=>0))}"><i class="fa fa-circle"></i> 拉黑会员</a>
                        <a class="btn btn-default disabled"  role="operate" data-type="3" data-title="取消拉黑" data-url="{:WebUrl('adminmember/operatemember',array('is_black'=>1))}"><i class="fa fa-circle-o"></i> 取消拉黑</a>
                    </div>
                    <div class="col-xs-4">
                        <form method="get">
                            <input type="text" name="key" class="form-control" placeholder="昵称">
                            <button type="submit" class="btn btn-default ">搜索</button>
                            <a class="btn btn-success ">导出</a>
                        </form>
                    </div>
                    <div class="col-xs-4 text-center">
                        <form method="get">
                            <input type="hidden" name="start_time" value="{:date('Y-m-d 00:00')}"/>
                            <input type="hidden" name="end_time" value="{:date('Y-m-d 23:59')}"/>
                            <input type="button" name="membertime" class="form-control " placeholder="按时间搜索" style="font-size: 12px;width: 240px;" >
                            <button type="submit" class="btn btn-default ">搜索</button>
                            <a class="btn btn-success ">导出</a>
                        </form>
                    </div>
                </div>
                <hr/>

                {php} if(!empty($memberlist)){ {/php}
                <table class="table">
                    <thead>
                    <tr role="row">
                        <th><input type="checkbox" value=""></th>
                        <th>会员名</th>
                        <th>帐号(手机)</th>
                        <th>等级/分组</th>
                        <th>积分/余额</th>
                        <th>成交</th>
                        <th>关注/黑名单</th>
                        <th>最近登录</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody >
                    {volist name='memberlist' id='member'}

                    <tr role="pop" data-title="会员ID:{$member['member_id']}" data-content="{php}if(!empty($member['parent_name'])){echo "推荐人<br/><a href='".WebUrl('adminmember/edit',array('member_id'=>$member['member_parent']))."'><label  class='label label-info' >".substr($member['parent_name'],0,5)."..</label></a>";}else{echo "推荐人<br/><a href='javascript:void(0);'><label class='label label-success'>商城</label></a>";}{/php}">
                        <td><input type="checkbox" value="{$member['member_id']}"></td>
                        <td><img src="{:toHeadurl($member['member_avatar'])}" class="img-circle " width="40px" height="40px"> {:substr($member['member_name'],0,20)}</td>
                        <td>{$member['member_mobile']}</td>
                        <td>
                            <p>普通等级</p>
                            <p>会员分组</p>
                        </td>
                        <td>
                            <p><span class="label label-success">积分:{$member['member_points']}</span></p>
                            <p><span class="label label-info">余额:{$member['available_predeposit']}元</span></p>
                        </td>
                        <td>
                            <p><span class="label label-success">订单:{$member['order_count']}</span></p>
                            <p><span class="label label-info">金额:{$member['order_sum']}元</span></p>
                        </td>
                        <td>
                            <p>{php}if($member['is_notice']){echo '<span class="label label-primary">已关注</span>';}else{echo '<span class="label label-default">未关注</span>';}{/php}</p>
                            <p>{php}if($member['member_state']){echo '<span class="label label-primary">正常</span>';}else{echo '<span class="label label-default">已拉黑</span>';}{/php}</p>
                        </td>
                        <td>
                            {:date('Y-m-d',$member['member_login_time'])}
                        </td>
                        <td>
                            <div class="btn-group">
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    操作 <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li><a href="javascript:void(0);"><i class="fa fa-pencil-square-o"></i> 会员编辑</a></li>
                                    <li><a href="javascript:void(0);"><i class="fa fa-th-list"></i> 会员订单</a></li>
                                    <li><a href="javascript:void(0);" onclick="showMoney({$member['member_id']},'{$member['member_name']}')"><i class="fa fa-money"></i> 充值金额</a></li>
                                    <li><a href="javascript:void(0);" onclick="showCredit({$member['member_id']},'{$member['member_name']}')"><i class="fa fa-credit-card"></i> 充值积分</a></li>
                                    <li><a href="javascript:void(0);" onclick="delmember({$member['member_id']})"><i class="fa fa-trash-o"></i> 删除会员</a></li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <div class="row-fluid">
                    <div class="span6 pull-right">
                        {$pagesion}
                    </div>
                </div>
                {php} }else{ {/php}
                    <div class="row text-center">暂无用户....</div>
                {php} } {/php}

            </div>
        </div>
    </div>
</section>
<!--充值积分-->
<div class="modal fade" id="creditModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" >会员充值</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="creditfrom" role="form">
                    <input type="hidden" name="credit_id" value="">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">会员名</label>
                        <div class="col-sm-10">
                            <p class="form-control" id="credit_name"></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">积分</label>
                        <div class="col-sm-10">
                            <input type="number" name="amount" class="form-control" placeholder="积分数">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <label class="radio-inline">
                                <input type="radio" name="credittype"  value="1" checked> 增加
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="credittype"  value="2"> 减少
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-10 ">
                            <textarea name="creditmessage" class="form-control"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="rechargeCredit();">充值</button>
            </div>
        </div>
    </div>
</div>
<!--充值余额-->
<div class="modal fade" id="moneyModal" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" >会员充值</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="moneyfrom">
                    <input type="hidden" name="money_id" value="">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">会员名</label>
                        <div class="col-sm-10 " >
                            <p class="form-control" id="money_name"></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">充值单号</label>
                        <div class="col-sm-10 " >
                            <input type="text" name="pdr_sn" class="form-control" placeholder="充值单号">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">金额</label>
                        <div class="col-sm-10">
                            <input type="number" name="amount" class="form-control" placeholder="金额">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-4 col-sm-offset-2">
                            <label class="radio-inline">
                                <input type="radio"  name="moneytype"  value="1" checked> 增加
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="moneytype"  value="2"> 减少
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">备注</label>
                        <div class="col-sm-10 ">
                            <textarea name="moneymessage" class="form-control"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="rechargeMoney()">充值</button>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        dateInit('input[name="membertime"]','input[name="start_time"]','input[name="end_time"]');
        $('[role="operate"]').click(function () {
            var title = $(this).data('title');
            var url = $(this).data('url');

            if(title){
                title = '您确认要执行此'+title+'操作吗？'
            }else{
                title = '您确认要执行此操作吗？'
            }
            $.confirm({
                icon:'fa fa-warning',
                title: '提醒',
                content: title ,
                buttons: {
                    ok: {
                        text: "确认",
                        btnClass: 'btn-success',
                        keys: ['enter'],
                        action: function(){
                            if( $('input[type="checkbox"]:checked').length>0){
                                var members = [];

                                $('input[type="checkbox"]:checked').each(function () {
                                    var id = $(this).val();
                                    members.push(id);
                                });
                                $.post(url,{member_id:members},function (data) {
                                    if(data.status==1){
                                        toastTop('操作成功');
                                        setTimeout(function () {
                                            window.location.reload();
                                        },600);
                                        return ;
                                    }else{
                                        toastTop('操作失败');
                                        return ;
                                    }

                                });
                            }else{
                                $.alert('没有选中的会员');
                                return false;
                            }
                        }
                    },
                    no:{
                        text: "取消",
                        btnClass: 'btn-default',
                        keys: ['enter'],
                        action: function(){
                            console.log('no');
                        }
                    },
                }
            });

        });
    });
    //充值积分
    function showCredit(id,name){
        $('input[name="credit_id"]').val(id);
        $('#credit_name').html(name);
        $('#creditModal').modal('show');
        return;
    }
    function rechargeCredit() {
        $('#creditModal').modal('hide');
        $.ajax({
                    cache: true,
                    type: "POST",
                    url:'{:WebUrl('adminmember/recharge',array('type'=>1))}',
                data:$('#creditfrom').serialize(),// 你的formid
                async: false,
                error: function(data) {
            toastTop('服务器错误，稍后再试',2);
        },
        success: function(data) {
            if(data.status==1){
                toastTop('充值成功');
                setTimeout(function(){
                    window.location='{:WebUrl('adminmember/index')}';
                },600);
            }else{
                toastTop('充值失败',2);
            }
        }
    },'json');
    }
    //充值金额
    function showMoney(id,name){
        $('input[name="money_id"]').val(id);
        $('#money_name').html(name);
        $('#moneyModal').modal('show');
        return ;
    }
    function rechargeMoney() {
        $('#moneyModal').modal('hide');
        $.ajax({
                    cache: true,
                    type: "POST",
                    url:'{:WebUrl('adminmember/recharge',array('type'=>2))}',
                data:$('#moneyfrom').serialize(),// 你的formid
                async: false,
                error: function(data) {
            toastTop('服务器错误，稍后再试',2);
        },
        success: function(data) {
            if(data.status==1){
                toastTop('充值成功');
                setTimeout(function(){
                    window.location='{:WebUrl('adminmember/index')}';
                },600);
            }else{
                toastTop('充值失败',2);
            }
        }
    },'json');

    }
    //删除会员
    function delmember(id) {
        if(!id){
            toastTop('没有找到此用户信息');
        }
        $.confirm({
            icon:'fa fa-warning',
            title: '提醒',
            content: '您确认要执行删除操作吗？' ,
            buttons: {
                ok: {
                    text: "确认",
                    btnClass: 'btn-success',
                    keys: ['enter'],
                    action: function(){
                        $.post('{:WebUrl('adminmember/del')}',{member_id:id},function (data) {
                            if(data.status==1){
                                toastTop('操作成功');
                                setTimeout(function () {
                                    window.location.reload();
                                },600);
                                return ;
                            }else{
                                toastTop('操作失败');
                                return ;
                            }

                        });
                    }
                },
                no:{
                    text: "取消",
                    btnClass: 'btn-default',
                    keys: ['enter'],
                    action: function(){
                        console.log('no');
                    }
                },
            }
        });
    }
</script>